package com.wedo.mall.activity.agent;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.e.library.activity.EActivity;
import com.e.library.http.EApi;
import com.e.library.http.EClient;
import com.e.library.http.EObserver;
import com.e.library.http.EResponse;
import com.e.library.widget.ETitleBar;
import com.wedo.mall.R;
import com.wedo.mall.activity.main.SearchActivity;
import com.wedo.mall.adapter.AgentCategoryAdapterX;
import com.wedo.mall.entity.AgentCategory;

import java.util.List;

import butterknife.BindView;

/**
 * 商家-更多店铺分类
 * Created by e on 2017/7/15.
 */

public class CategoriesActivity extends EActivity {

    @BindView(R.id.title_bar) ETitleBar title_bar;
    @BindView(R.id.rv_category) RecyclerView rv_category;

    @Override
    protected int layout() {
        return R.layout.activity_categories;
    }

    @Override
    protected void onActivityCreated(Bundle state) {

        rv_category.setHasFixedSize(false);
        rv_category.setNestedScrollingEnabled(false);
        rv_category.setLayoutManager(new GridLayoutManager(this, 4));
        listener();
        categories();
    }

    /**商品分类*/
    private void categories() {

        loading();
        EClient.with().post(EApi.AGENT_CATEGORY, new EObserver() {
            @Override
            public void successful(EResponse response) {
                List<AgentCategory> list = response.list(AgentCategory.class);
                AgentCategoryAdapterX adapter = new AgentCategoryAdapterX(CategoriesActivity.this, list);
                rv_category.setAdapter(adapter);
                adapter.listener(CategoriesActivity.this);
            }

            @Override
            public void failure(String msg) {
                toast(msg);
            }

            @Override
            public void onComplete() {
                super.onComplete();
                dismiss();
            }
        });
    }

    protected void listener(){
        title_bar.setOnForwardListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SearchActivity.toSearchAgent(CategoriesActivity.this);
            }
        });
    }
}
